Intro flextable()

Aula 9, M2

Carolina Musso

Sala de Situação - UnB

Esta semana

Aula 8 - Manipulação lihas e colunas

Função select() e filter()

Aula 9 - Tabelas

Introdução ao pacote flextable - confeccionar uma tabela simples a partir da seleção e filtros.

Leituras para aprofundamento

flextable

  • Gosto muito para arquivos em:

    • word (.doc), mas também funciona em .html e .pdf

Mas há outros pacotes para tabelas famosos:

Dados de hoje

 brasil_italia <- dados_covid %>% 
  select(Date_reported, Country,New_cases, New_deaths) %>% # 
  filter(Country=="Brazil"|Country=="Italy",
         New_cases >15000,
         New_deaths<30 )

 brasil_italia
  Date_reported Country New_cases New_deaths
1    2022-06-06  Brazil     15590         26
2    2022-08-02  Brazil     20313         28
3    2022-05-30   Italy     15136         27
4    2022-06-06   Italy     15522         27
5    2022-06-13   Italy     19310         26
6    2022-06-20   Italy     34255         18
7    2022-09-11   Italy     15563         18
8    2022-09-26   Italy     18794         13
9    2022-10-03   Italy     28906         20

flextable

flextable( brasil_italia)

# ou

dados_covid %>% 
  select(Date_reported, Country,New_cases, New_deaths) %>% # 
  filter(Country=="Brazil"|Country=="Italy",
         New_cases >15000,
         New_deaths<30 ) %>% 
  flextable()

Tab1

Lógica…

Gosto de pensar que também funciona como “camadas”.

  • alinhamento
  • fonte
  • largura
  • cores…
funcao_edicao_flextable(objeto,
                        parâmetro="opcao", 
                        i=numero_da_linha,
                        j=numero_da_coluna, 
                        part="header"/"body"/"all" )`

width : Largura

  • só funciona para as colunas (afinal as colunas que têm largura)
flextable( brasil_italia) %>% 
  width(width=3)

Tab2

  • Se não especificar j ele faz para todas!
flextable(brasil_italia) %>% 
  width(width=3) %>% 
  width (j=1, width=2) 

Tab3

flextable(brasil_italia) %>% 
  width(width=4) %>% 
   width (j=1, width=1) %>% 
   width (j=4, width=1) 

# OU - MELHOR

flextable(brasil_italia) %>% 
  width(width=4) %>% 
   width (j=c(1,4), width=1) 

Tab4

bold: Negrito

  • podemos usar a mesma lógica para as colunas

  • Mas com o negrito, e outras formatações internas podemos também trabalhar nas linhas.

  • j eram as colunas …

  • i são as linhas

Destacar Linhas

flextable(brasil_italia) %>% 
  width(width=3) %>% 
  width (j=1, width=2) %>% 
  bold (i=5)

Tab5

flextable(brasil_italia) %>% 
  width(width=3) %>% 
  width (j=1, width=2) %>% 
  bold (i=5) %>% 
   bold (part = "header")

Tab6

alinhamento

flextable(brasil_italia) %>% 
  width(width=3) %>% 
  width (j=1, width=2) %>% 
  bold (i=5) %>% 
  bold (part = "header") %>% 
  align(align="center", part="all")

Tab7

Ainda não tá muito bonito…

  • Calma!
  • Aprenderemos mais edições em outras aulas!
  • Próxima aula, função para criar novas variáveis! A mutate()

Até lá!